﻿<Window x:Class="Meridian.Views.MainView"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:Properties="clr-namespace:Meridian.Properties"
        Title="{Binding Title}" Height="600" Width="800" MinWidth="550" MinHeight="575"
        WindowStyle="None" ResizeMode="CanMinimize"  AllowsTransparency="True" Background="Transparent" AllowDrop="True"
        MouseMove="WindowMouseMove" SourceInitialized="WindowSourceInitialized" Closing="WindowClosing">
    <Window.TaskbarItemInfo>
        <TaskbarItemInfo x:Name="Taskbar">
            <TaskbarItemInfo.ThumbButtonInfos>
                <ThumbButtonInfo x:Name="ThumbShuffleButton" IsEnabled="{Binding IsLoaded}" ImageSource="/Meridian;component/Resources/Images/shuffle_disabled_icon_thumb.png" Click="ThumbShuffleButtonClick"/>
                <ThumbButtonInfo x:Name="ThumbPrevButton" IsEnabled="{Binding IsLoaded}" ImageSource="/Meridian;component/Resources/Images/prev_thumb.png" Click="ThumbPrevButtonClick"/>
                <ThumbButtonInfo x:Name="ThumbPlayButton" IsEnabled="{Binding IsLoaded}" ImageSource="/Meridian;component/Resources/Images/play_thumb.png" Click="ThumbPlayButtonClick"/>
                <ThumbButtonInfo x:Name="ThumbNextButton" IsEnabled="{Binding IsLoaded}" ImageSource="/Meridian;component/Resources/Images/next_thumb.png" Click="ThumbNextButtonClick"/>
            </TaskbarItemInfo.ThumbButtonInfos>
        </TaskbarItemInfo>
    </Window.TaskbarItemInfo>
    <Window.Triggers>
        <EventTrigger RoutedEvent="Window.Loaded">
            <BeginStoryboard>
                <Storyboard>
                    <Storyboard>
                        <DoubleAnimationUsingKeyFrames Storyboard.TargetName="ControlsGrid" Storyboard.TargetProperty="Opacity">
                            <EasingDoubleKeyFrame KeyTime="0" Value="0"/>
                            <EasingDoubleKeyFrame KeyTime="0:0:0.6" Value="1">
                                <EasingDoubleKeyFrame.EasingFunction>
                                    <ExponentialEase EasingMode="EaseOut" Exponent="6"/>
                                </EasingDoubleKeyFrame.EasingFunction>
                            </EasingDoubleKeyFrame>
                        </DoubleAnimationUsingKeyFrames>
                        <DoubleAnimationUsingKeyFrames Storyboard.TargetName="ControlsGrid" Storyboard.TargetProperty="(RenderTransform).X">
                            <EasingDoubleKeyFrame KeyTime="0" Value="-50"/>
                            <EasingDoubleKeyFrame KeyTime="0:0:0.8" Value="0">
                                <EasingDoubleKeyFrame.EasingFunction>
                                    <ExponentialEase EasingMode="EaseOut" Exponent="6"/>
                                </EasingDoubleKeyFrame.EasingFunction>
                            </EasingDoubleKeyFrame>
                        </DoubleAnimationUsingKeyFrames>
                        <!--<DoubleAnimationUsingKeyFrames Storyboard.TargetName="ControlsGrid" Storyboard.TargetProperty="Opacity" DecelerationRatio="0.3">
                            <LinearDoubleKeyFrame KeyTime="0" Value="0"/>
                            <LinearDoubleKeyFrame KeyTime="0:0:0.5" Value="1"/>
                        </DoubleAnimationUsingKeyFrames>
                        <DoubleAnimationUsingKeyFrames Storyboard.TargetName="ControlsGrid" Storyboard.TargetProperty="(RenderTransform).X" DecelerationRatio="0.3">
                            <LinearDoubleKeyFrame KeyTime="0" Value="-50"/>
                            <LinearDoubleKeyFrame KeyTime="0:0:0.5" Value="0"/>
                        </DoubleAnimationUsingKeyFrames>-->
                    </Storyboard>
                    <Storyboard>
                        <DoubleAnimationUsingKeyFrames Storyboard.TargetName="CurrentAudioGrid" Storyboard.TargetProperty="Opacity">
                            <DiscreteDoubleKeyFrame KeyTime="0" Value="0"/>
                            <DiscreteDoubleKeyFrame KeyTime="0:0:0.2" Value="0"/>
                            <EasingDoubleKeyFrame KeyTime="0:0:0.7" Value="1">
                                <EasingDoubleKeyFrame.EasingFunction>
                                    <ExponentialEase EasingMode="EaseOut" Exponent="6"/>
                                </EasingDoubleKeyFrame.EasingFunction>
                            </EasingDoubleKeyFrame>
                        </DoubleAnimationUsingKeyFrames>
                        <DoubleAnimationUsingKeyFrames Storyboard.TargetName="CurrentAudioGrid" Storyboard.TargetProperty="(RenderTransform).X">
                            <DiscreteDoubleKeyFrame KeyTime="0" Value="-50"/>
                            <DiscreteDoubleKeyFrame KeyTime="0:0:0.2" Value="-50"/>
                            <EasingDoubleKeyFrame KeyTime="0:0:0.7" Value="0">
                                <EasingDoubleKeyFrame.EasingFunction>
                                    <ExponentialEase EasingMode="EaseOut" Exponent="6"/>
                                </EasingDoubleKeyFrame.EasingFunction>
                            </EasingDoubleKeyFrame>
                        </DoubleAnimationUsingKeyFrames>
                        <!--<DoubleAnimationUsingKeyFrames Storyboard.TargetName="CurrentAudioGrid" Storyboard.TargetProperty="Opacity" DecelerationRatio="0.3">
                            <LinearDoubleKeyFrame KeyTime="0:0:0.0" Value="0"/>
                            <LinearDoubleKeyFrame KeyTime="0:0:0.3" Value="0"/>
                            <LinearDoubleKeyFrame KeyTime="0:0:0.8" Value="1"/>
                        </DoubleAnimationUsingKeyFrames>
                        <DoubleAnimationUsingKeyFrames Storyboard.TargetName="CurrentAudioGrid" Storyboard.TargetProperty="(RenderTransform).X" DecelerationRatio="0.3">
                            <LinearDoubleKeyFrame KeyTime="0:0:0.3" Value="-50"/>
                            <LinearDoubleKeyFrame KeyTime="0:0:0.8" Value="0"/>
                        </DoubleAnimationUsingKeyFrames>-->
                    </Storyboard>
                    <Storyboard>
                        <DoubleAnimationUsingKeyFrames Storyboard.TargetName="SearchBoxGrid" Storyboard.TargetProperty="Opacity">
                            <DiscreteDoubleKeyFrame KeyTime="0" Value="0"/>
                            <DiscreteDoubleKeyFrame KeyTime="0:0:0.4" Value="0"/>
                            <EasingDoubleKeyFrame KeyTime="0:0:0.8" Value="1">
                                <EasingDoubleKeyFrame.EasingFunction>
                                    <ExponentialEase EasingMode="EaseOut" Exponent="6"/>
                                </EasingDoubleKeyFrame.EasingFunction>
                            </EasingDoubleKeyFrame>
                        </DoubleAnimationUsingKeyFrames>
                        <DoubleAnimationUsingKeyFrames Storyboard.TargetName="SearchBoxGrid" Storyboard.TargetProperty="(RenderTransform).X">
                            <DiscreteDoubleKeyFrame KeyTime="0" Value="-50"/>
                            <DiscreteDoubleKeyFrame KeyTime="0:0:0.4" Value="-50"/>
                            <EasingDoubleKeyFrame KeyTime="0:0:0.8" Value="0">
                                <EasingDoubleKeyFrame.EasingFunction>
                                    <ExponentialEase EasingMode="EaseOut" Exponent="6"/>
                                </EasingDoubleKeyFrame.EasingFunction>
                            </EasingDoubleKeyFrame>
                        </DoubleAnimationUsingKeyFrames>
                        <!--<DoubleAnimationUsingKeyFrames Storyboard.TargetName="SearchBoxGrid" Storyboard.TargetProperty="Opacity" DecelerationRatio="0.3">
                            <LinearDoubleKeyFrame KeyTime="0:0:0.0" Value="0"/>
                            <LinearDoubleKeyFrame KeyTime="0:0:0.5" Value="0"/>
                            <LinearDoubleKeyFrame KeyTime="0:0:0.9" Value="1"/>
                        </DoubleAnimationUsingKeyFrames>
                        <DoubleAnimationUsingKeyFrames Storyboard.TargetName="SearchBoxGrid" Storyboard.TargetProperty="(RenderTransform).X" DecelerationRatio="0.3">
                            <LinearDoubleKeyFrame KeyTime="0:0:0.5" Value="-50"/>
                            <LinearDoubleKeyFrame KeyTime="0:0:0.9" Value="0"/>
                        </DoubleAnimationUsingKeyFrames>-->
                    </Storyboard>
                </Storyboard>
            </BeginStoryboard>
        </EventTrigger>
    </Window.Triggers>
    <Grid Name="RootGrid" Margin="15">
        <Rectangle Fill="Black" Margin="-1" Opacity="0.8">
            <Rectangle.Effect>
                <BlurEffect Radius="15" />
            </Rectangle.Effect>
        </Rectangle>
        <Rectangle Fill="White"/>
        <MediaElement Name="MediaElement" Visibility="Collapsed" LoadedBehavior="Manual" Source="{Binding CurrentAudio.Url}"/>
        <ProgressBar Name="LoadingProgressBar" Style="{StaticResource MetroProgressBarStyle}" Foreground="{StaticResource AccentColor}" IsIndeterminate="{Binding IsLoading}" Visibility="{Binding IsLoading, Converter={StaticResource VisibilityConverter}, ConverterParameter=Visible}" VerticalAlignment="Top" Padding="0" Margin="0,2,0,0"/>

        <Button Name="MeridianButton" HorizontalAlignment="Left" Height="27" VerticalAlignment="Top" Width="122" Click="MeridianButtonClick">
            <Button.Template>
                <ControlTemplate TargetType="Button">
                    <Grid>
                        <Rectangle x:Name="Bg" Fill="{StaticResource AccentColor}"/>
                        <DockPanel>
                            <Image DockPanel.Dock="Right" Source="/Resources/Images/settings_icon.png" Width="12" Margin="0,0,10,0"/>
                            <TextBlock VerticalAlignment="Center" HorizontalAlignment="Center" Foreground="White" FontSize="13">
                                <Run Text="MERIDIAN"  FontFamily="../Fonts/#Segoe WP Semilight"/>
                                <Run Text="beta"  FontFamily="../Fonts/#Segoe WP Semibold" FontSize="10"/>
                            </TextBlock>
                        </DockPanel>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter Property="Fill" TargetName="Bg" Value="{StaticResource MeridianButtonOverBrush}"/>
                        </Trigger>
                        <Trigger Property="IsPressed" Value="True">
                            <Setter Property="Fill" TargetName="Bg" Value="{StaticResource MeridianButtonPressBrush}"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Button.Template>
        </Button>
        <Grid VerticalAlignment="Top" Margin="0,0,0,0" HorizontalAlignment="Right">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="36"/>
                <ColumnDefinition Width="100"/>
            </Grid.ColumnDefinitions>
            <StackPanel Margin="0,0,5,0">
                <TextBlock Name="UsernameTextBlock" Text="{Binding UserName}" HorizontalAlignment="Right" FontSize="14" FontWeight="Medium"/>
                <TextBlock  Text="{Binding UserLastName}" HorizontalAlignment="Right" FontSize="12" FontWeight="Light"/>
            </StackPanel>
            <Rectangle Fill="{StaticResource AccentColor}" HorizontalAlignment="Right" Grid.Column="1" Width="36" Height="36"/>
            <Image Source="{Binding UserPicture}" HorizontalAlignment="Right" Grid.Column="1" Width="36" Height="36"/>
            <StackPanel Grid.Column="2" Orientation="Horizontal" VerticalAlignment="Top" HorizontalAlignment="Right" Margin="10">
                <Button Style="{StaticResource MiniModeButtonStyle}" Margin="0,0,10,0" ToolTip="{x:Static Properties:Resources.MiniTooltip}" Click="MiniModeButtonClick"/>
                <Button Style="{StaticResource MinimizeButtonStyle}" VerticalAlignment="Bottom" ToolTip="{x:Static Properties:Resources.MinimizeTooltip}" Margin="0,0,10,0" Click="MinimizeButtonClick"/>
                <!--<ToggleButton Style="{StaticResource MaximizeButtonStyle}" Margin="10,0,10,0" Click="MaximizeButtonClick"/>-->
                <Button Style="{StaticResource CloseButtonStyle}" ToolTip="{x:Static Properties:Resources.CloseTooltip}" Click="CloseButtonClick"/>
            </StackPanel>
        </Grid>
        <Rectangle Fill="{StaticResource AccentColor}" VerticalAlignment="Top" Height="2"/>
        <Grid Margin="0,38,0,0">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="3"/>
                <RowDefinition Height="*"/>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition x:Name="LeftColumn" Width="*"/>
                <ColumnDefinition Width="5"/>
                <ColumnDefinition x:Name="RightColumn" Width="*"/>
            </Grid.ColumnDefinitions>
            <TextBlock Text="{x:Static Properties:Resources.MyAudio}" FontSize="21" Margin="10,0,0,0" FontFamily="../Fonts/#Segoe WP Light"/>
            <ListBox Name="MyAudioList" Grid.Row="2" ItemTemplate="{StaticResource MyAudioItemTemplate}" ItemContainerStyle="{StaticResource MetroListboxItemStyle}" HorizontalContentAlignment="Stretch" 
                     ItemsSource="{Binding MyAudio}" BorderThickness="0" SelectedIndex="{Binding MyAudioSelectedIndex}" KeyDown="MyAudioListKeyDown"
                     ScrollViewer.ScrollChanged="MyAudioListScrollChanged" SelectionChanged="MyAudioListSelectionChanged">
                <ListBox.ContextMenu>
                    <ContextMenu>
                        <ContextMenu.Items>
                            <MenuItem Name="RemoveItem" Header="{x:Static Properties:Resources.RemoveItem}" Click="RemoveItemClick"/>
                            <MenuItem Name="LeftHideItem" Header="{x:Static Properties:Resources.HideItem}" Click="LeftHideItemClick"/>
                            <MenuItem Name="LeftRestoreItem" Header="{x:Static Properties:Resources.RestoreItem}" Visibility="Collapsed" Click="LeftRestoreItemClick"/>
                        </ContextMenu.Items>
                    </ContextMenu>
                </ListBox.ContextMenu>
            </ListBox>
            <DockPanel Grid.Column="2" Grid.RowSpan="3">
                <Grid Name="SearchBoxGrid" DockPanel.Dock="Top" Margin="0,5,5,0">
                    <Grid.RenderTransform>
                        <TranslateTransform />
                    </Grid.RenderTransform>
                    <TextBox Name="SearchBox" Text="{x:Static Properties:Resources.Search}" Padding="10,3,25,3" HorizontalAlignment="Stretch" Style="{StaticResource MetroTextBoxStyle}"
                         FontFamily="../Fonts/#Segoe WP SemiBold" FontSize="16" KeyDown="SearchBoxKeyDown" GotFocus="SearchBoxGotFocus" LostFocus="SearchBoxLostFocus"/>
                    <Image Name="SearchIcon" Source="{StaticResource SearchIcon}" Width="14" Margin="5,5,10,5" HorizontalAlignment="Right" MouseLeftButtonUp="SearchIconMouseLeftButtonUp"/>
                </Grid>
                <ListBox Grid.Column="1" Name="SearchList" Grid.Row="2" ItemTemplate="{StaticResource SearchAudioItemTemplate}" ItemContainerStyle="{StaticResource MetroListboxItemStyle}" HorizontalContentAlignment="Stretch" 
                     ItemsSource="{Binding SearchResults, NotifyOnTargetUpdated=True}" BorderThickness="0" SelectedIndex="{Binding SearchSelectedIndex}" KeyDown="SearchListKeyDown"
                         ScrollViewer.ScrollChanged="SearchListScrollChanged" SelectionChanged="SearchListSelectionChanged" TargetUpdated="SearchListTargetUpdated">
                    <ListBox.ContextMenu>
                        <ContextMenu>
                            <ContextMenu.Items>
                                <MenuItem Name="AddItem" Header="{x:Static Properties:Resources.AddItem}" Click="AddItemClick"/>
                                <MenuItem Name="RightHideItem" Header="{x:Static Properties:Resources.HideItem}" Click="RightHideItemClick"/>
                                <MenuItem Name="RightRestoreItem" Header="{x:Static Properties:Resources.RestoreItem}" Visibility="Collapsed" Click="RightRestoreItemClick"/>
                            </ContextMenu.Items>
                        </ContextMenu>
                    </ListBox.ContextMenu>
                </ListBox>
            </DockPanel>
            <Grid Grid.ColumnSpan="3" Grid.Row="3">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>

                <Grid Name="ControlsGrid" HorizontalAlignment="Right" VerticalAlignment="Bottom" Margin="10,20,20,5" Grid.Column="2">
                    <Grid.RenderTransform>
                        <TranslateTransform />
                    </Grid.RenderTransform>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto"/>
                        <ColumnDefinition Width="Auto"/>
                        <ColumnDefinition Width="5*"/>
                        <ColumnDefinition Width="Auto"/>
                        <ColumnDefinition Width="20"/>
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                    </Grid.RowDefinitions>
                    <ToggleButton Name="ShuffleButton" Template="{StaticResource Shuffle}" Width="14" Height="14" IsEnabled="{Binding IsLoaded}" ToolTip="{x:Static Properties:Resources.ShuffleTooltip}" Margin="0,0,10,0" IsChecked="{Binding Shuffle}"/>
                    <Button Name="PrevButton" Grid.Column="1" Template="{StaticResource Prev}" Width="26" IsEnabled="{Binding IsLoaded}" ToolTip="{x:Static Properties:Resources.PrevTooltip}" Click="PrevButtonClick"/>
                    <ToggleButton Name="PlayPauseButton" Grid.Column="2" Template="{StaticResource PlayPause}" Margin="5,0,5,0" Width="36" ToolTip="{x:Static Properties:Resources.PlayPauseTooltip}" IsEnabled="{Binding IsLoaded}" IsChecked="{Binding IsPlaying, Mode=OneWay}" Click="PlayPauseButtonClick"/>
                    <Button Name="NextButton" Grid.Column="3" Template="{StaticResource Next}" Width="26" IsEnabled="{Binding IsLoaded}" ToolTip="{x:Static Properties:Resources.NextTooltip}" Click="NextButtonClick"/>
                    <DockPanel Grid.ColumnSpan="5" Grid.Row="1">
                        <Image Source="/Resources/Images/volume_icon.png" Width="15" Opacity="0.5"/>
                        <TextBlock Text="{Binding ElementName=VolumeSlider, Path=Value, Mode=OneWay, StringFormat=N0}" DockPanel.Dock="Right" FontFamily="../Fonts/#Segoe WP Light" Width="22"/>
                        <Slider Name="VolumeSlider" Style="{StaticResource MetroSlider}" IsMoveToPointEnabled="True" Foreground="{StaticResource AccentColor}" Background="LightGray" Value="{Binding Volume}" Maximum="100"
                                Margin="3,0,3,0"/>
                    </DockPanel>
                </Grid>
                <Grid Name="CurrentAudioGrid" VerticalAlignment="Center" Grid.Column="1">
                    <Grid.RenderTransform>
                        <TranslateTransform />
                    </Grid.RenderTransform>
                    <Grid.RowDefinitions>
                        <RowDefinition />
                        <RowDefinition Height="14"/>
                        <RowDefinition />
                    </Grid.RowDefinitions>
                    <DockPanel>
                        <ToggleButton Name="LikeButton" DockPanel.Dock="Right" Template="{StaticResource Favourite}" Width="18" Cursor="Hand" IsEnabled="{Binding CanLike}" Click="LikeButtonClick" IsChecked="{Binding CurrentAudio.IsAddedByUser, Mode=OneWay}"/>
                        <TextBlock Name="PlayingTitle" Text="{Binding CurrentAudio.FullTitle}" FontSize="12" FontFamily="../Fonts/#Segoe WP" VerticalAlignment="Center" Foreground="Gray" TextTrimming="CharacterEllipsis" Margin="0,0,5,0"/>
                    </DockPanel>
                    <Slider Grid.Row="1" Name="ProgressSlider" IsEnabled="{Binding IsLoaded}" Style="{StaticResource MetroSlider}" IsMoveToPointEnabled="True" Foreground="{StaticResource AccentColor}" Background="LightGray"
                            Value="{Binding Position.TotalSeconds, Mode=OneWay}" Maximum="{Binding Duration.TotalSeconds, Mode=OneWay}" ValueChanged="ProgressSliderValueChanged"/>
                    <TextBlock Grid.Row="2" Name="EstimatedTime" Text="{Binding Position, Mode=OneWay, StringFormat=m\\:ss}" FontSize="12" FontFamily="../Fonts/#Segoe WP" HorizontalAlignment="Left" Foreground="Gray"/>
                    <TextBlock Grid.Row="2" Name="LeftTime" Text="{Binding TimeLeft, Mode=OneWay, StringFormat=m\\:ss}" FontSize="12" FontFamily="../Fonts/#Segoe WP" HorizontalAlignment="Right" Foreground="Gray"/>
                </Grid>
                <TextBlock Text="{Binding Status}" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="20,0,20,0" MaxHeight="45" FontSize="11" TextWrapping="Wrap" TextTrimming="CharacterEllipsis" FontFamily="../Fonts/#Segoe WP" Foreground="Gray"/>
            </Grid>
        </Grid>
        <Grid Name="SettingsHost" Visibility="Collapsed" Margin="0,38,0,0"/>
        <ResizeGrip Cursor="SizeNWSE" HorizontalAlignment="Right" VerticalAlignment="Bottom" MouseMove="ResizeGripMouseMove"/>
    </Grid>
</Window>
